const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    getInput: '',
    dataList: '',
    search_his_list: []
  },
  goPrepage: function () {
    wx.switchTab({
      url: "../index/index"
    })
  },
  getInput: function (e) {
    this.setData({ getInput: e.detail.value });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var self = this;
    wx.request({
      url: app.globalData.ApiUrl + '/index.php?act=index&op=search_key_list',
      success(res) {
        self.setData({
          dataList: res.data.datas
        })
      }
    })

  },
  onShow: function () {
    wx.getStorage({
      key: 'search_his_list',
      success: (res) => {
        this.setData({
          search_his_list: res.data
        })
      }
    })
  },
  clear_his: function () {
    wx.setStorage({
      key: 'search_his_list',
      data: []
    })
    this.setData({
      search_his_list: []
    })
  },
  searchComfir: function () {
    if (this.data.getInput) {
      wx.navigateTo({
        url: "../search/search?keyword=" + this.data.getInput
      })
    } else {
      if (this.data.dataList.hot_info.value) {
        wx.navigateTo({
          url: "../search/search?keyword=" + this.data.dataList.hot_info.value
        })
      } else {
        wx.showToast({
          title: '请输入搜索内容',
          icon: 'none'
        })
      }

    }
  }
})